package com.yangrd.airship.upms.support;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * description: AuthorizeDefine
 *
 * @author: yangrd
 * @date: 2021/6/24
 * @version: 1.0
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Getter
@EqualsAndHashCode(of = "name")
@RequiredArgsConstructor(staticName = "of")
public class AuthorizeDefine {

    final String name;

    final String operation;

    final String authority;

    final Set<AuthorizeDefine> children;

    Map<String, Object> meta;

    public synchronized void addChildren(AuthorizeDefine define) {
        children.add(define);
    }

    public synchronized void addMeta(String key, Object val) {
        if (Objects.isNull(meta)) {
            meta = new HashMap<>(6);
        }
        meta.put(key, val);
    }
}
